import axios from 'axios';


const axiosInstance = axios.create({
    baseURL: '/api',//基础url，会在请求地址上自动缀在最前面
});

// Add a response interceptor 拦截响应
axiosInstance.interceptors.response.use(function (response) {
    console.log("拦截：",response);
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data

    const result = response.data;

    if(result.success){
        return result;//改变axios响应的正向函数的参数
    }

    //showFailToast(result.message);

    throw new Error(response);

}, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
});

export default axiosInstance;
